﻿using HomagGroup.Base;
using HomagGroup.Base.Interfaces;
using HomagGroup.Base.UI;
using HomagChina.Nesting.Views;
using Proxy;
using System;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using Utility;
using hgw = HomagGroup.Base.UI.Windows;

namespace HomagChina.Nesting
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private SingleInstanceApplication _Mutex;
        private ErrorHandler errorHandler;
        private hgw.SplashScreenWindow _SplashScreenWindow;

        public App()
        {
            _Mutex = new SingleInstanceApplication();
            if (_Mutex.IsAnyOtherInstanceRunning())
            {
                _Mutex.ActivateOtherInstance();
                Environment.Exit(-1);
            }

            var msgRep = new DefaultMessageReporter();
            errorHandler = new ErrorHandler(msgRep);
        }

        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            _SplashScreenWindow = new hgw.SplashScreenWindow();
            _SplashScreenWindow.OnStartup("HOMAG Group Nesting", Assembly.GetExecutingAssembly().GetName().Version.ToString(), "Nesting", "ZBOM Nesting", "© 2023 - 2024 HOMAG Group CellControlTransport");
            await Task.Delay(3000);
            //InitPlc();
            //DealWithBatchFile dealWithBatchFile = new DealWithBatchFile();
            //InfeedHandle infeedHandle = new InfeedHandle();
            _SplashScreenWindow.Close();
            var m = new MainWindow();
            m.DataContext = new MainWindowViewModel(errorHandler);
            m.Show();
        }

        /// <summary>
        ///
        /// </summary>
        public void InitPlc()
        {
            PlcHandle plcHandle = new PlcHandle(Globle.ProviderId, "192.3.60.12.1.1", 851);
            SerilogHandle.Logger_System.Information("与PLC建立链接");
        }
    }
}